//- Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
//- <https://www.chatopera.com>, Licensed under the Chunsong Public
//- License, Version 1.0  (the "License"), https://docs.cskefu.com/licenses/v1.html
//- Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
//- Copyright (C) 2018-Jun. 2023 Chatopera Inc, <https://www.chatopera.com>
//- Licensed under the Apache License, Version 2.0
//- http://www.apache.org/licenses/LICENSE-2.0
#agents_status.agent-title
    | 服务中的人数：#{agentStatusReport.users}人，当前排队人数：#{agentStatusReport.inquene}人，在线坐席数：#{agentStatusReport.agents}人，坐席忙：#{agentStatusReport.busy}人
#agentstatus.layui-unselect.layui-form-switch.checkStatus.lay-filter(class={
    'layui-form-onswitch': agentStatus.status == 'ready',
    'layui-form-offswitch': agentStatus.status != 'ready'
})
    i.checkStatusI
a.iframe_btn(href="javascript:void(0)" onclick="return false;" data-title="首页" data-href="/apps/content.html" data-id="maincontent" data-type="tabChange" style="display: none;")
    i.kfont(style="position: relative;") 
    |    首页
#agentstatus_busy.layui-unselect.layui-form-switch.layui-form-onswitch-notbusy(style=agentStatus ? '' : 'display:none',class={'layui-form-onswitch-busy': agentStatus.busy})
    i
script.
    $('#agentstatus').on("click", function () {
        if ($(this).hasClass('layui-form-onswitch')) { // 从就绪到非就绪
            checkAgentStatusData().then(function (data) {
                return handleAgentStatusData(data);
            }).then(function (data) {
                if (data.length > 0) {
                    // 还有服务中的访客
                    layer.confirm('您有正在服务中的访客' + data.length + '人，转为非就绪状态将不可邀请访客，不会分配新访客。', {
                        btn: ['切换', '取消'], icon: 4, title: '提示',
                        cancel: function (index, layero) {
                            //点击关闭按钮
                        }
                    }, function (index, layero) {
                        // 不分配
                        setAgentAsNotReady();
                        layer.close(index);
                    }, function (index) {
                        layer.close(index);
                    });
                } else {
                    // 没有服务中的访客直接切换状态
                    // 切换坐席状态为未就绪
                    setAgentAsNotReady();
                }
            });
        } else { // 从非就绪到就绪
            setAgentAsReady();
        }
    });
    // 请求并将坐席置为就绪状态
    function setAgentAsReady() {
        $("#agentstatus").addClass("layui-form-onswitch");
        sessionStorage.setItem(agentstatus, "ready")
        loadURL("/agent/ready.html", null, function () {
            $('#agentstatus_busy').show();
        });
    }
    // 请求并将坐席置为非就绪状态
    function setAgentAsNotReady() {
        $('#agentstatus').removeClass("layui-form-onswitch");
        sessionStorage.setItem(agentstatus, "notready");
        loadURL("/agent/notready.html", null, function () {
            $('#agentstatus_busy').removeClass("layui-form-onswitch-busy").hide();
        });
    }
    $('#agentstatus_busy').on("click", function () {
        if ($(this).hasClass('layui-form-onswitch-busy')) {
            $(this).removeClass("layui-form-onswitch-busy");
            $(this).addClass("layui-form-onswitch-notbusy");
            loadURL("/agent/notbusy.html")
        } else {
            $(this).removeClass("layui-form-onswitch-notbusy");
            $(this).addClass("layui-form-onswitch-busy");
            loadURL("/agent/busy.html");
        }
    });
